﻿using Compass.Wasm.Shared;
using Compass.Wasm.Shared.Wms;
using System.Collections.Generic;

namespace Compass.Wpf.ApiServices.Wms;
public interface ICargoService:IBaseService<CargoDto>
{
    Task<ApiResponse<CargoDto>> GetSingleByMtlNumberAsync(string mtlNumber);
    Task<ApiResponse<List<CargoDto>>> GetAllByAreaAsync(Warehouse_e warehouse, Area_e area,string ranks);
    Task<ApiResponse<CargoDto>> GetSingleByLocationAsync(string location);
    //带库存的查询
    Task<ApiResponse<List<CargoDto>>> GetTop5ByKeywordWithInventoryAsync(string? keyword);
    Task<ApiResponse<CargoDto>> GetFirstOrDefaultWithInventoryAsync(Guid id);
    Task<ApiResponse<List<CargoDto>>> GetAllWithInventoryAsync();
    Task<ApiResponse<List<CargoDto>>> GetAllByAreaWithInventoryAsync(Warehouse_e warehouse, Area_e area, string ranks);
}
public class CargoService:BaseService<CargoDto>,ICargoService
{
    private readonly HttpRestClient _client;
    private const string ServiceName = "Cargo";
    public CargoService(HttpRestClient client) : base(client, ServiceName)
    {
        _client = client;
    }

    public async Task<ApiResponse<CargoDto>> GetSingleByMtlNumberAsync(string mtlNumber)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/MtlNumber?mtlNumber={mtlNumber}"
        };
        return await _client.ExecuteAsync<CargoDto>(request);
    }

    public async Task<ApiResponse<List<CargoDto>>> GetAllByAreaAsync(Warehouse_e warehouse, Area_e area,string ranks)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/Area?warehouse={warehouse}&area={area}&ranks={ranks}"
        };
        return await _client.ExecuteAsync<List<CargoDto>>(request);
    }

    public async Task<ApiResponse<CargoDto>> GetSingleByLocationAsync(string location)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/Location?location={location}"
        };
        return await _client.ExecuteAsync<CargoDto>(request);
    }


    //带库存的查询方法
    public async Task<ApiResponse<List<CargoDto>>> GetTop5ByKeywordWithInventoryAsync(string? keyword)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/Inventory/Top5?keyword={keyword}"
        };
        return await _client.ExecuteAsync<List<CargoDto>>(request);
    }

    public async Task<ApiResponse<CargoDto>> GetFirstOrDefaultWithInventoryAsync(Guid id)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/Inventory/{id}"
        };
        return await _client.ExecuteAsync<CargoDto>(request);
    }
    public async Task<ApiResponse<List<CargoDto>>> GetAllWithInventoryAsync()
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/Inventory/All"
        };
        return await _client.ExecuteAsync<List<CargoDto>>(request);
    }
    public async Task<ApiResponse<List<CargoDto>>> GetAllByAreaWithInventoryAsync(Warehouse_e warehouse, Area_e area, string ranks)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/Inventory/Area?warehouse={warehouse}&area={area}&ranks={ranks}"
        };
        return await _client.ExecuteAsync<List<CargoDto>>(request);
    }


}